package com.zhangfb95.crosschain.infra.controller.starter.httplog;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zhangfubing
 * @since 2019/5/25
 */
@Configuration
@EnableConfigurationProperties(StarterProperties.class)
public class StarterAutoConfigure implements WebMvcConfigurer {

    @Autowired
    private StarterProperties properties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        if (properties.isEnabled()) {
            registry.addInterceptor(new DefaultHandlerInterceptor(properties));
        }
    }
}
